package com.ocom.mqsimple.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


//错误人脸处理

@Lazy
@Component
@Configuration
public class FaceErrConfig {

	// 业务队列
	public static final String FACE_ERR_QUEUE = "face_err_queue";

	// 业务交换机
	public static final String FACE_ERR_EXCHANGE = "face_err_exchange";

	// 死信队列
	public static final String FACE_ERR_DIE_QUEUE = "face_err_die_queue";
	// 死信交换机
	public static final String FACE_ERR_DIE_EXCHANGE = "face_err_die_exchange";


	//声明一个死信队列用来存放死信消息
	@Bean
	public Queue faceErrDieQueue() {
		return new Queue(FACE_ERR_DIE_QUEUE,true,false,false,null);
	}
	//声明一个死信交换机
	@Bean
	public TopicExchange faceErrDieExchange() {
		return new TopicExchange(FACE_ERR_DIE_EXCHANGE,true,true);
	}

	//将死信队列和死信的交换机绑定
	@Bean
	public Binding faceErrQueueBindingDieExchange() {
		return BindingBuilder.bind(faceErrDieQueue()).
				to(faceErrDieExchange()).
				with("dieRoutingKeys");
	}

	//声明一个业务队列
	@Bean
	public Queue faceErrQueue() {
		Map<String, Object> args = new HashMap<>();
		// 声明  死信队列Exchange
		args.put("x-dead-letter-exchange", FACE_ERR_DIE_EXCHANGE);
		// 设置死信routingKey
		args.put("x-dead-letter-routing-key", "dieRoutingKeys");

		//优先级队列
		args.put("x-max-priority", 100);

		return new Queue(
				FACE_ERR_QUEUE,
				true,
				false,
				false, args);
	}

	//声明一个业务交换机
	@Bean
	public TopicExchange faceErrExchange() {
		return new TopicExchange(FACE_ERR_EXCHANGE);
	}

	//将业务队列和业务交换机绑定
	@Bean
	public Binding faceErrBindingDirect() {
		return BindingBuilder.bind(faceErrQueue()).to(faceErrExchange()).with("routingKeys");
	}










}

